//
//  QJKaiDianVC.m
//  QuanJieShopProject
//
//  Created by apple on 2018/2/27.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJKaiDianVC.h"
#import "QJKaiDianVCHeaderView.h"
#import "QJKaiDianVCTwo.h"
#import "YFUserStatusAndTypeTool.h"
@interface QJKaiDianVC ()
{
    // -1  未找到店铺   新用户注册就是这个
    NSInteger _userState; //  0 未审核  1 审核通过  2 审核未通过
    NSInteger _user_type;  // 1 是 泉界会员，2 是泉界创客，3，是泉界商家
}
@property (nonatomic, strong) QJKaiDianVCHeaderView *kdHeaderView;
@property (nonatomic, strong) UITableView *kdTableView;
@end

@implementation QJKaiDianVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupKaiDianVCAction];
    
//    [YFSaveTool userDefaults:@"rootVC" key:@"KD"];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [YFUserStatusAndTypeTool fetchUserStatus:^(NSInteger status, NSInteger userType) {
        _userState = status;
        _user_type = userType;
    }];
    
}

- (void)setupKaiDianVCAction{
    self.title = @"开店";
    self.kdHeaderView = [[[NSBundle mainBundle]loadNibNamed:@"QJKaiDianVCHeaderView" owner:self options:nil]firstObject];
    [self.kdHeaderView setupHeaderUIAction];
    NSString *str = self.kdHeaderView.contentLabel.text;
    CGFloat labelHeight = [YFGlobalTool sizeWithString:str font:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(UISCREEN_WIDTH - 20, MAXFLOAT)].height;
    self.kdHeaderView.frame = CGRectMake(0, 0, UISCREEN_WIDTH, labelHeight + 200);
    self.kdHeaderView.nextBtnClickBlockAction = ^{

        // 判断是否登录
        if ([QJUserInfo isLogin]) {
    
//            // 测试
//            QJKaiDianVCTwo *VC = [[QJKaiDianVCTwo alloc]init];
//            KPushViewControllerAction(VC);
//            return;
//            // 测试结束
            
//            if (_userState == 0) {  // 未审核
//                [MBPHUD showAlertWithTitle:@"正在审核,请耐心等待!"];
//            }else if (_userState == 1) {  // 审核通过
//                [MBPHUD showAlertWithTitle:@"您已经是泉界商家了，无需再次注册开店!"];
//            }else if (_userState == 2 || _userState == -1) {  // 审核未通过
                QJKaiDianVCTwo *VC = [[QJKaiDianVCTwo alloc]init];
                KPushViewControllerAction(VC);
//            }
            
        }else{
            [MBPHUD showAlertWithTitle:@"您还没有登录,请去登录!"];
        }
      
    };
    
    self.kdTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.kdTableView];
    self.kdTableView.tableHeaderView = self.kdHeaderView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
